package gouroutine_pool

import (
	"errors"
	"time"
)

type DefaultTaskFactory struct {
}

func (f *DefaultTaskFactory) NewTask(run runFunc, param interface{}, timeOut int, timeUnit time.Duration, callBack runFunc, mata string) (*Task, error) {
	if run == nil {
		return nil, errors.New("call method is rerequied")
	}

	if callBack != nil {
		return fullArgsTask(run, param, timeOut, timeUnit, callBack, mata), nil
	}
	return defaultTask(run, param, mata), nil
}

// 默认的构造方法
func defaultTask(run runFunc, param interface{}, mata string) *Task {
	return NewTask(run, param, 10, time.Second, nil, mata)
}

func fullArgsTask(run runFunc, param interface{}, timeOut int, timeUnit time.Duration, callBack runFunc, mata string) *Task {
	return NewTask(run, param, timeOut, timeUnit, callBack, mata)
}
